package com.he.test;

/**
 * @description: TODO
 * @Author: HCL
 * @Date: 2024/10/24 8:36
 */
public class SyncSingleton {

    //1 私有构造
    private SyncSingleton(){

    }

    //2 定义私有静态对象，并用volatile关键字修饰
    private static volatile SyncSingleton singleton;

    //3 提供创建对象的方法
    public static SyncSingleton getInstance(){
        if (singleton == null){
            synchronized (SyncSingleton.class){
                if (singleton == null){
                    singleton = new SyncSingleton();
                }
            }
        }
        return singleton;
    }

    public void show(){
        System.out.println("懒汉");
    }
}
